//
//  WelfareHeaderView.swift
//  TianTianBiTing
//
//  Created by Gox mac 2 on 2019/2/22.
//  Copyright © 2019 Gox_WallyDiao. All rights reserved.
//

import UIKit

class WelfareHeaderView: UIView {
    var noticeStr:String?
    var checkBlock:(() -> Void)?
    var noticeLabel:UILabel = UILabel.init()
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        self.backgroundColor = UIColor.clear
        setUI()
        setData()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func setUI() {
        
        let backImageView = UIImageView.init(frame: FRAME_CGFloat(20, 0, SCREEN_WIDTH - 40, 45))
        self.addSubview(backImageView)
        backImageView.isUserInteractionEnabled = true
        backImageView.image = IMAGE(name: "welfareBack")
        
        let noticeImage = UIImageView.init(frame: FRAME_CGFloat(16, 16, 13, 13))
        backImageView.addSubview(noticeImage)
        noticeImage.image = IMAGE(name: "welfareNotice")
        
        self.noticeLabel.frame = FRAME_CGFloat(30, 12, SCREEN_WIDTH - 140, 20)
        self.noticeLabel.font = Font_Bold(14)
        self.noticeLabel.textColor = WhiteBackColor
        self.noticeLabel.numberOfLines = 1
        backImageView.addSubview(self.noticeLabel)
        
        let checkBtn = UIButton.init(type: .custom)
        checkBtn.setImage(IMAGE(name: "welfareCheck"), for: .normal)
        backImageView.addSubview(checkBtn)
        checkBtn.frame = FRAME_CGFloat(SCREEN_WIDTH - 100, 5, 50, 35)
        checkBtn.addTarget(self, action: #selector(checkAction), for: .touchUpInside)
        
    }
    
    func setData() {
        MineRequestModel.loadWalletBalance(jointArr: [String.getUserId()]) { (success, message, left, right) in
            if success {
                self.noticeLabel.text = "您还有\(String.money(right) ?? "0.00")元听币没有提现"
            }
        }
    }
    
    @objc func checkAction() {
        checkBlock?()

    }

    /*
    // Only override draw() if you perform custom drawing.
    // An empty implementation adversely affects performance during animation.
    override func draw(_ rect: CGRect) {
        // Drawing code
    }
    */

}
